{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/melih/anaconda3/envs/spon/lib/python3.11/site-packages/langchain_experimental/utilities/__init__.py:3: LangChainDeprecationWarning: As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. The langchain.pydantic_v1 module was a compatibility shim for pydantic v1, and should no longer be used. Please update the code to import from Pydantic directly.\n",
      "\n",
      "For example, replace imports like: `from langchain.pydantic_v1 import BaseModel`\n",
      "with: `from pydantic import BaseModel`\n",
      "or the v1 compatibility namespace if you are working in a code base that has not been fully upgraded to pydantic 2 yet. \tfrom pydantic.v1 import BaseModel\n",
      "\n",
      "  from langchain_experimental.utilities.python import PythonREPL\n"
     ]
    }
   ],
   "source": [
    "from demogpt_agenthub.agents import ToolCallingAgent\n",
    "from demogpt_agenthub.llms import OpenAIChatModel\n",
    "from demogpt_agenthub.tools import DuckDuckGoSearchTool, WeatherTool\n",
    "search_tool = DuckDuckGoSearchTool()\n",
    "weather_tool = WeatherTool()\n",
    "llm = OpenAIChatModel(model_name=\"gpt-4o-mini\")\n",
    "agent = ToolCallingAgent(tools=[search_tool, weather_tool], llm=llm, verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reasoning:\n",
      "\u001b[94mThe user is asking for current weather information in Tokyo, which is best obtained using the OpenWeatherMap tool as it provides specific data about weather conditions.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mopen_weather_map\u001b[0m\n",
      "Tool result:\n",
      "\u001b[92mIn Tokyo, the current weather is as follows:\n",
      "Detailed status: heavy intensity rain\n",
      "Wind speed: 6.17 m/s, direction: 200°\n",
      "Humidity: 45%\n",
      "Temperature: \n",
      "  - Current: 23.55°C\n",
      "  - High: 24.25°C\n",
      "  - Low: 22.56°C\n",
      "  - Feels like: 23.14°C\n",
      "Rain: {'1h': 5.05}\n",
      "Heat index: None\n",
      "Cloud cover: 75%\u001b[0m\n",
      "Answer:\n",
      "\u001b[92mThe current weather in Tokyo is as follows: \n",
      "\n",
      "- **Condition**: Heavy intensity rain\n",
      "- **Wind Speed**: 6.17 m/s (from the direction of 200°)\n",
      "- **Humidity**: 45%\n",
      "- **Temperature**: \n",
      "  - Current: 23.55°C\n",
      "  - High: 24.25°C\n",
      "  - Low: 22.56°C\n",
      "  - Feels like: 23.14°C\n",
      "- **Rain**: 5.05 mm in the last hour\n",
      "- **Cloud Cover**: 75%\n",
      "\n",
      "Stay dry out there!\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'The current weather in Tokyo is as follows: \\n\\n- **Condition**: Heavy intensity rain\\n- **Wind Speed**: 6.17 m/s (from the direction of 200°)\\n- **Humidity**: 45%\\n- **Temperature**: \\n  - Current: 23.55°C\\n  - High: 24.25°C\\n  - Low: 22.56°C\\n  - Feels like: 23.14°C\\n- **Rain**: 5.05 mm in the last hour\\n- **Cloud Cover**: 75%\\n\\nStay dry out there!'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "agent.run(\"What is the weather in Tokyo?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reasoning:\n",
      "\u001b[94mThe task is to calculate a number raised to the power of another. The most appropriate tool for this calculation is MyPowerTool, which is specifically designed for power calculations.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mMyPowerTool\u001b[0m\n",
      "Tool result:\n",
      "\u001b[92m6583424253569334549714045134721532297216\u001b[0m\n",
      "Answer:\n",
      "\u001b[92m34 to the power of 26 is 6583424253569334549714045134721532297216.\u001b[0m\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'34 to the power of 26 is 6583424253569334549714045134721532297216.'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from demogpt_agenthub.tools import BaseTool\n",
    "class MyPowerTool(BaseTool):\n",
    "    def __init__(self):\n",
    "        self.name = \"MyPowerTool\"\n",
    "        self.description = \"This tool is used to calculate the power of a number\"\n",
    "        super().__init__()\n",
    "    def run(self, a: int, b: int):\n",
    "        # Implement your tool's functionality here\n",
    "        return a**b\n",
    "\n",
    "power_tool = MyPowerTool()\n",
    "agent = ToolCallingAgent(tools=[search_tool, weather_tool, power_tool], llm=llm, verbose=True)\n",
    "agent.run(\"What is the 34 to the power of 26?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Here are some videos about the 2024 presidential election:\\n\\n1. [Video 1](https://www.youtube.com/watch?v=HYE20qmGIbg&pp=ygUaMjAyNCBwcmVzaWRlbnRpYWwgZWxlY3Rpb24%3D)\\n2. [Video 2](https://www.youtube.com/watch?v=eFCiva4m3Zk&pp=ygUaMjAyNCBwcmVzaWRlbnRpYWwgZWxlY3Rpb24%3D)\\n\\nFeel free to check them out for more information!'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from demogpt_agenthub.tools.youtube import YouTubeSearchTool\n",
    "youtube_tool = YouTubeSearchTool()\n",
    "agent = ToolCallingAgent(tools=[youtube_tool], llm=llm, verbose=False)\n",
    "agent.run(\"List the videos about the 2024 presidential election\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decision:\n",
      "\u001b[95mFalse\u001b[0m\n",
      "Reasoning:\n",
      "\u001b[94mFirst, I need to determine the current location where Christiano Ronaldo is playing in order to fetch the current temperature. Then I will use the OpenWeatherMap tool to get the temperature information. Finally, I will calculate the square root of the temperature using the Python Interpreter tool for precise computation.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mduckduckgo_search\u001b[0m\n",
      "Tool args:\n",
      "\u001b[93m{'inp': 'Where is Christiano Ronaldo currently playing?'}\u001b[0m\n",
      "Tool result:\n",
      "\u001b[92mRonaldo started Al Nassr's home match against Saudi Pro League leaders Al Ittihad on May 7. Stefano Pioli's men went into a 2-0 first-half lead but were beaten 3-2 when Houssem Aouar stuck in ... Cristiano Ronaldo and his Al Nassr team endured disappointment in 2023/24 as they failed to win the Saudi Pro League or the AFC Champions League. After Sadio Mane, Seko Fofana, Marcelo Brozovic ... Yes, Cristiano Ronaldo will be in the lineup to play tonight. Now that they once again failed to win the AFC Champions League Elite, Ronaldo will still have some optimism that they can win the league despite being eight points behind Al Ittihad. Despite the club's poor season, Ronaldo has maintained his goalscoring form, netting 23 goals in ... Cristiano Ronaldo currently plays for Al Nassr in the Saudi Pro League. The Portugal international transferred from Manchester United in December 2022 and inked a two-and-a-half-year contract with ... Is Cristiano Ronaldo playing Today? Cristiano Ronaldo is expected to start in today's crucial match. The Portuguese star remains Al Nassr's top scorer in the AFC Champions League, with six goals to his name. His outstanding form has played a pivotal role in the team's journey to the semifinals—now just one win away from reaching a continental final for the first time since 1995, when ...\u001b[0m\n",
      "Decision:\n",
      "\u001b[95mFalse\u001b[0m\n",
      "Reasoning:\n",
      "\u001b[94mI need to fetch the current temperature in Saudi Arabia where Cristiano Ronaldo is playing, using the OpenWeatherMap tool. After obtaining the temperature, I will compute its square root using the Python Interpreter tool.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mopen_weather_map\u001b[0m\n",
      "Tool args:\n",
      "\u001b[93m{'city': 'Riyadh,SA'}\u001b[0m\n",
      "Tool result:\n",
      "\u001b[92mIn Riyadh,SA, the current weather is as follows:\n",
      "Detailed status: clear sky\n",
      "Wind speed: 5.44 m/s, direction: 150°\n",
      "Humidity: 7%\n",
      "Temperature: \n",
      "  - Current: 39.16°C\n",
      "  - High: 39.16°C\n",
      "  - Low: 39.16°C\n",
      "  - Feels like: 35.82°C\n",
      "Rain: {}\n",
      "Heat index: None\n",
      "Cloud cover: 0%\u001b[0m\n",
      "Decision:\n",
      "\u001b[95mFalse\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Python REPL can execute arbitrary code. Use with caution.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reasoning:\n",
      "\u001b[94mI need to calculate the square root of the current temperature in Saudi Arabia, which is 39.16°C. I will use the Python Interpreter tool for precise calculation.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mPython Interpreter\u001b[0m\n",
      "Tool args:\n",
      "\u001b[93m{'code': 'import math\\nresult = math.sqrt(39.16)\\nprint(result)'}\u001b[0m\n",
      "Tool result:\n",
      "\u001b[92m6.257795138864806\n",
      "\u001b[0m\n",
      "Decision:\n",
      "\u001b[95mTrue\u001b[0m\n",
      "Answer:\n",
      "\u001b[92mThe square root of the current temperature in Saudi Arabia, where Cristiano Ronaldo is playing, is approximately 6.26.\u001b[0m\n",
      "The square root of the current temperature in Saudi Arabia, where Cristiano Ronaldo is playing, is approximately 6.26.\n"
     ]
    }
   ],
   "source": [
    "from demogpt_agenthub.tools import DuckDuckGoSearchTool, WeatherTool, PythonTool\n",
    "from demogpt_agenthub.llms import OpenAIChatModel\n",
    "from demogpt_agenthub.agents import ReactAgent\n",
    "search_tool = DuckDuckGoSearchTool()\n",
    "weather_tool = WeatherTool()\n",
    "python_tool = PythonTool()\n",
    "agent = ReactAgent(tools=[search_tool, weather_tool, python_tool], llm=OpenAIChatModel(model_name=\"gpt-4o-mini\"), verbose=True)\n",
    "query = \"What is the weather's temperature's square root in the country where Christiano Ronaldo is currently playing? Please precisely calculate the result.\"\n",
    "print(agent.run(query))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/melih/anaconda3/envs/spon/lib/python3.11/site-packages/langchain_experimental/utilities/__init__.py:3: LangChainDeprecationWarning: As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. The langchain.pydantic_v1 module was a compatibility shim for pydantic v1, and should no longer be used. Please update the code to import from Pydantic directly.\n",
      "\n",
      "For example, replace imports like: `from langchain.pydantic_v1 import BaseModel`\n",
      "with: `from pydantic import BaseModel`\n",
      "or the v1 compatibility namespace if you are working in a code base that has not been fully upgraded to pydantic 2 yet. \tfrom pydantic.v1 import BaseModel\n",
      "\n",
      "  from langchain_experimental.utilities.python import PythonREPL\n",
      "USER_AGENT environment variable not set, consider setting it to identify your requests.\n",
      "/home/melih/anaconda3/envs/spon/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "INFO:numexpr.utils:Note: NumExpr detected 32 cores but \"NUMEXPR_MAX_THREADS\" not set, so enforcing safe limit of 16.\n",
      "INFO:numexpr.utils:NumExpr defaulting to 16 threads.\n",
      "INFO:sentence_transformers.SentenceTransformer:Use pytorch device_name: cuda:0\n",
      "INFO:sentence_transformers.SentenceTransformer:Load pretrained SentenceTransformer: sentence-transformers/all-mpnet-base-v2\n",
      "INFO:chromadb.telemetry.product.posthog:Anonymized telemetry enabled. See                     https://docs.trychroma.com/telemetry for more information.\n"
     ]
    }
   ],
   "source": [
    "from demogpt_agenthub.rag import BaseRAG\n",
    "from demogpt_agenthub.llms import OpenAIChatModel\n",
    "\n",
    "rag = BaseRAG(llm=OpenAIChatModel(model=\"gpt-4o-mini\"), \n",
    "                  vectorstore=\"chroma\", \n",
    "                  persistent_path=\"rag_chroma\", \n",
    "                  index_name=\"rag_index\",\n",
    "                  reset_vectorstore=True,\n",
    "                  embedding_model_name=\"sentence-transformers/all-mpnet-base-v2\",\n",
    "                  filter={\"search_kwargs\": {\"score_threshold\": 0.5}}\n",
    "                  )\n",
    "rag.add_files([\"~/Downloads/Melih_ÜNSAL_Resume.pdf\"]) # Add your file paths here"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:chromadb.segment.impl.vector.local_persistent_hnsw:Number of requested results 4 is greater than number of elements in index 3, updating n_results = 3\n",
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'The GitHub repository of Melih is called DemoGPT, and it can be found at the following URL: [https://github.com/melih-unsal](https://github.com/melih-unsal).'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rag.run(\"What is the github repo of Melih?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:chromadb.segment.impl.vector.local_persistent_hnsw:Number of requested results 4 is greater than number of elements in index 3, updating n_results = 3\n",
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'The GitHub repo of Melih has 1.8K stars.'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rag.run(\"How many stars does the github repo of Melih have?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:chromadb.segment.impl.vector.local_persistent_hnsw:Number of requested results 4 is greater than number of elements in index 3, updating n_results = 3\n",
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'The latest company Melih has worked at is Micro1, where he held the position of LLM & AI Engineer.'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rag.run(\"What is the latest company Melih has worked at?\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Add RAG to the agent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/melih/anaconda3/envs/spon/lib/python3.11/site-packages/langchain_experimental/utilities/__init__.py:3: LangChainDeprecationWarning: As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. The langchain.pydantic_v1 module was a compatibility shim for pydantic v1, and should no longer be used. Please update the code to import from Pydantic directly.\n",
      "\n",
      "For example, replace imports like: `from langchain.pydantic_v1 import BaseModel`\n",
      "with: `from pydantic import BaseModel`\n",
      "or the v1 compatibility namespace if you are working in a code base that has not been fully upgraded to pydantic 2 yet. \tfrom pydantic.v1 import BaseModel\n",
      "\n",
      "  from langchain_experimental.utilities.python import PythonREPL\n",
      "USER_AGENT environment variable not set, consider setting it to identify your requests.\n",
      "/home/melih/anaconda3/envs/spon/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n",
      "INFO:numexpr.utils:Note: NumExpr detected 32 cores but \"NUMEXPR_MAX_THREADS\" not set, so enforcing safe limit of 16.\n",
      "INFO:numexpr.utils:NumExpr defaulting to 16 threads.\n",
      "INFO:sentence_transformers.SentenceTransformer:Use pytorch device_name: cuda:0\n",
      "INFO:sentence_transformers.SentenceTransformer:Load pretrained SentenceTransformer: sentence-transformers/all-mpnet-base-v2\n",
      "INFO:chromadb.telemetry.product.posthog:Anonymized telemetry enabled. See                     https://docs.trychroma.com/telemetry for more information.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Removing existing vectorstore at rag_chroma\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decision:\n",
      "\u001b[95mFalse\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
      "WARNING:chromadb.segment.impl.vector.local_persistent_hnsw:Number of requested results 4 is greater than number of elements in index 3, updating n_results = 3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reasoning:\n",
      "\u001b[94mTo find the square root of the number of stars in Melih's GitHub repo, I first need to retrieve the current number of stars for that repository. After obtaining that number, I can compute its square root. The RAG tool will help me find out the number of stars, and then I'll use the Python Interpreter to calculate the square root.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mRAG\u001b[0m\n",
      "Tool args:\n",
      "\u001b[93m{'query': 'number of stars in the GitHub repository of Melih'}\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Tool result:\n",
      "\u001b[92mThe GitHub repository of Melih ÜNSAL has 1.8K stars.\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decision:\n",
      "\u001b[95mFalse\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",
      "WARNING:langchain_experimental.utilities.python:Python REPL can execute arbitrary code. Use with caution.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reasoning:\n",
      "\u001b[94mI need to calculate the square root of 1.8K stars, which is equivalent to 1800 stars. To perform this calculation, I will use the Python Interpreter tool to compute the square root.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mPython Interpreter\u001b[0m\n",
      "Tool args:\n",
      "\u001b[93m{'code': 'import math\\nresult = math.sqrt(1800)\\nprint(result)'}\u001b[0m\n",
      "Tool result:\n",
      "\u001b[92m42.42640687119285\n",
      "\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decision:\n",
      "\u001b[95mTrue\u001b[0m\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Answer:\n",
      "\u001b[92mThe square root of the number of stars in Melih's GitHub repository, which is 1.8K (or 1800 stars), is approximately 42.43.\u001b[0m\n",
      "The square root of the number of stars in Melih's GitHub repository, which is 1.8K (or 1800 stars), is approximately 42.43.\n"
     ]
    }
   ],
   "source": [
    "from demogpt_agenthub.tools import PythonTool\n",
    "from demogpt_agenthub.llms import OpenAIChatModel\n",
    "from demogpt_agenthub.agents import ReactAgent\n",
    "from demogpt_agenthub.rag import BaseRAG\n",
    "\n",
    "rag = BaseRAG(llm=OpenAIChatModel(model=\"gpt-4o-mini\"), \n",
    "                  vectorstore=\"chroma\", \n",
    "                  persistent_path=\"rag_chroma\", \n",
    "                  index_name=\"rag_index\",\n",
    "                  reset_vectorstore=True,\n",
    "                  embedding_model_name=\"sentence-transformers/all-mpnet-base-v2\",\n",
    "                  filter={\"search_kwargs\": {\"score_threshold\": 0.5}}\n",
    "                  )\n",
    "rag.add_files([\"~/Downloads/Melih_ÜNSAL_Resume.pdf\"])\n",
    "python_tool = PythonTool()\n",
    "agent = ReactAgent(tools=[python_tool, rag], llm=OpenAIChatModel(model_name=\"gpt-4o-mini\"), verbose=True)\n",
    "query = \"What is the square root of the number of stars of the github repo of Melih?\"\n",
    "print(agent.run(query))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/melih/anaconda3/envs/spon/lib/python3.11/site-packages/langchain_experimental/utilities/__init__.py:3: LangChainDeprecationWarning: As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. The langchain.pydantic_v1 module was a compatibility shim for pydantic v1, and should no longer be used. Please update the code to import from Pydantic directly.\n",
      "\n",
      "For example, replace imports like: `from langchain.pydantic_v1 import BaseModel`\n",
      "with: `from pydantic import BaseModel`\n",
      "or the v1 compatibility namespace if you are working in a code base that has not been fully upgraded to pydantic 2 yet. \tfrom pydantic.v1 import BaseModel\n",
      "\n",
      "  from langchain_experimental.utilities.python import PythonREPL\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Decision:\n",
      "\u001b[95mFalse\u001b[0m\n",
      "Reasoning:\n",
      "\u001b[94mThe task is to identify and list the objects present in a given image. The available tool, 'YOLO Object Detection', is specifically designed for this purpose and can analyze the image to output detailed descriptions of detected objects.\u001b[0m\n",
      "Tool call:\n",
      "\u001b[93mYOLO Object Detection\u001b[0m\n",
      "Tool args:\n",
      "\u001b[93m{'path': 'https://ultralytics.com/images/bus.jpg'}\u001b[0m\n",
      "\n",
      "Found https://ultralytics.com/images/bus.jpg locally at bus.jpg\n",
      "image 1/1 /home/melih/Desktop/projects/DemoGPT/bus.jpg: 640x480 4 persons, 1 bus, 59.1ms\n",
      "Speed: 2.0ms preprocess, 59.1ms inference, 38.9ms postprocess per image at shape (1, 3, 640, 480)\n",
      "Tool result:\n",
      "\u001b[92min the image.\n",
      "There are 1 bus, 4 person in the image.\n",
      "The bus[1] is from (3, 229) to (796, 728).\n",
      "The person[1] is from (671, 394) to (809, 878).\n",
      "The person[2] is from (47, 399) to (239, 904).\n",
      "The person[3] is from (223, 408) to (344, 860).\n",
      "The person[4] is from (0, 556) to (68, 872).\n",
      "\u001b[0m\n",
      "Decision:\n",
      "\u001b[95mTrue\u001b[0m\n",
      "Answer:\n",
      "\u001b[92mIn the image you provided, there are the following objects detected:\n",
      "\n",
      "- 1 bus\n",
      "- 4 persons\n",
      "\n",
      "The bus is located at coordinates from (3, 229) to (796, 728). The persons are located at the following coordinates:\n",
      "\n",
      "- Person 1: (671, 394) to (809, 878)\n",
      "- Person 2: (47, 399) to (239, 904)\n",
      "- Person 3: (223, 408) to (344, 860)\n",
      "- Person 4: (0, 556) to (68, 872)\u001b[0m\n",
      "In the image you provided, there are the following objects detected:\n",
      "\n",
      "- 1 bus\n",
      "- 4 persons\n",
      "\n",
      "The bus is located at coordinates from (3, 229) to (796, 728). The persons are located at the following coordinates:\n",
      "\n",
      "- Person 1: (671, 394) to (809, 878)\n",
      "- Person 2: (47, 399) to (239, 904)\n",
      "- Person 3: (223, 408) to (344, 860)\n",
      "- Person 4: (0, 556) to (68, 872)\n"
     ]
    }
   ],
   "source": [
    "from demogpt_agenthub.tools import YoloTool\n",
    "from demogpt_agenthub.llms import OpenAIChatModel\n",
    "from demogpt_agenthub.agents import ReactAgent\n",
    "\n",
    "yolo_tool = YoloTool()\n",
    "\n",
    "agent = ReactAgent(tools=[yolo_tool], llm=OpenAIChatModel(model_name=\"gpt-4o-mini\"), verbose=True)\n",
    "query = \"Give me the objects in the image https://ultralytics.com/images/bus.jpg\"\n",
    "print(agent.run(query))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "spon",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
